package com.briup.upload.web.controller;

import com.briup.common.web.Message;
import com.briup.common.web.MessageUtil;
import com.briup.logging.annotation.LoggingAccess;
import com.briup.upload.service.IUploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@Api(tags = "zip文件上传模块,使用POSTMAN测试")
@LoggingAccess("文件上传模块")
@RestController
@Data
@RequestMapping("/upload")
public class UploadController {

    @Autowired
    private IUploadService uploadService;
    @PostMapping(value="/zip",consumes = "multipart/form-data")
    @LoggingAccess("上传zip压缩文件")
    @ApiOperation("上传文件，支持本地和远程上传")
    @ApiImplicitParams({
            @ApiImplicitParam(name="zip",value="文件",paramType = "form",dataType = "__file",allowMultiple = true),
            @ApiImplicitParam(name="datasetId",value="数据集ID",paramType = "form",dataType = "String"),
    })
    public Message uploadZip(@RequestParam("zip") MultipartFile[] zip,
                             @RequestParam("datasetId") String datasetId){
        uploadService.upload(zip,datasetId);
        return MessageUtil.success();
    }

    @PostMapping(value="/image",consumes = "multipart/form-data")
    @LoggingAccess("上传单张图片")
    @ApiOperation("给指定数据集下的指定分类中，上传单张文件，支持本地和远程上传")
    @ApiImplicitParams({
            @ApiImplicitParam(name="image",value="图片",paramType = "form",dataType = "__file"),
            @ApiImplicitParam(name="datasetId",value="数据集ID",paramType = "form",dataType = "String"),
            @ApiImplicitParam(name="classifyId",value="分类ID",paramType = "form",dataType = "String"),
    })
    public Message uploadZip(@RequestParam("image") MultipartFile image,
                             @RequestParam("datasetId") String datasetId,
                             @RequestParam("classifyId") String classifyId){
        uploadService.upload(image,datasetId,classifyId);
        return MessageUtil.success();
    }

}
